const http = require("http");
const fs = require("fs");
const path = require("path");

const server = http.createServer((req, res) => {
  // console.log(req.url);

  const { url } = req;

  switch (url) {
    case "/index":
      fs.readFile(
        path.join(__dirname, "./index.html"),
        "utf-8",
        (err, data) => {
          if (err) throw err;
          res.write(data);
          res.end();
        }
      );
      break;
    case "/login":
      fs.readFile(
        path.join(__dirname, "./login.html"),
        "utf-8",
        (err, data) => {
          if (err) throw err;
          res.write(data);
          res.end();
        }
      );
      break;
    case "/style.css":
      fs.readFile(path.join(__dirname, "./style.css"), "utf-8", (err, data) => {
        if (err) throw err;
        res.write(data);
        res.end();
      });
      break;
    default:
      return;
  }
});

server.listen(3000);
